﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;

namespace HY.BLL.pub
{
    public class pubwhere
    {
        /// <summary>
        /// 返回当前用户和当前表，查询条件
        /// </summary>
        /// <param name="nm"></param>
        /// <param name="tab"></param>
        /// <returns></returns>
        public static DataTable get_where(string nm, string tab)
        {
            string sqltxt = "select * from pub_where where wtab='" + tab + "' and wuser='" + nm + "'";
            DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
            return dt;
        }


        public static string get_where_sql(string nm, string tab)
        {
            string wh = "";
            string sqltxt = "select * from pub_where where wtab='" + tab + "' and wuser='" + nm + "'";
            DataTable dt = DAL.DbHelperSQL.SqlDataAdapter(sqltxt);
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                wh = wh + dt.Rows[i]["wwhere"].ToString();
                if (i <dt.Rows.Count-1)  wh = wh +" and ";
            }
           
              return wh;
        }


        //写入查询条件
        public static int  ins_where(string nm, string tab,string val,string txt)
        {
            string sqltxt = "insert pub_where values(N'" + tab + "' ,N'" + nm + "' ,N'" + val + "',N'" + txt + "')";
            return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);     

        }

        //删除查询条件
        public static int del_where(string nm, string tab)
        {
            string sqltxt = "delete pub_where where wtab='" + tab + "' and wuser='" + nm + "'";
            return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
        }

        //删除查询条件
        public static int del_where(string where)
        {
            string sqltxt = "delete pub_where where sid in(" + where + ")";
            return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
        }

        //删除查询条件
        public static int del_where_user(string nm)
        {
            string sqltxt = "delete pub_where where  wuser='" + nm + "'";
            return DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);
        }
    }
}

